package com.twu.biblioteca.factory;

import com.twu.biblioteca.BibliotecaApp;
import com.twu.biblioteca.Println;
import com.twu.biblioteca.Receiver;
import com.twu.biblioteca.Shelf;

public  class BasicAction {

    public void run(BibliotecaApp bibliotecaApp, Receiver receiver) {

    }

    public String inputQueryGoodsName(Receiver receiver, Shelf shelf){
        Println.println(Println.INPUT_CHOOSE_NAME);
        String chooseBookName = receiver.getData();
        while (!shelf.isExist(chooseBookName)) {
            Println.println(Println.INVALID_OPTION);
            chooseBookName = receiver.getData();
        }
        return chooseBookName;
    }

    protected String inputValidBorrowGoodsName(Receiver receiver, Shelf shelf) {
        Println.println(Println.INPUT_CHOOSE_NAME);
        String choose = receiver.getData();
        while (!shelf.isExist(choose) || shelf.isBorrowed(choose)) {
            Println.println(Println.FAIL_BORROW);
            choose = receiver.getData();
        }
        return choose;
    }

    protected String inputValidReturnBookName(Receiver receiver, Shelf shelf) {
        Println.println(Println.INPUT_CHOOSE_NAME);
        String bookName = receiver.getData();
        while (!shelf.isExist(bookName)) {
            Println.println(Println.FAIL_RETURN_BOOK);
            bookName = receiver.getData();
        }
        return bookName;
    }
}
